const { request } = require("../../utils/request.js")

let page = 1;
let finish = false;

Page({
  data: {
    list: [],
    recommendList: [],
  },
  // 请求数据
  onLoad() {
    this.getBannerList();
    this.getRecommendList();
  },
  getBannerList() {
    request("/home/banner").then(res => {
      this.setData({
        list: res.data.result.list
      })
    })
  },
  getRecommendList() {
    request("/home/recommend", "POST", { count: 3, page: page }).then(res => {
      this.setData({
        recommendList: res.data.result.list
      })
      page++;
    })
  },
  goDetail() {
    wx.navigateTo({
      // 小程序里面只能使用query传参，在onLoad的options里面获取
      url: '../../packageA/pages/detail/detail?id=345',
    })
  },
  onReachBottom() {
    if (!finish) {
      request("/home/recommend", "POST", { count: 3, page: page }).then(res => {
        this.setData({
          recommendList: [...this.data.recommendList, ...res.data.result.list]
        })
        page++
        if (res.data.result.list < 3) {
          finish = true
        }
      })
    }
    
  },
})
